<?php


// scripts
echo $html->script('/admin/js/jquery_plugins/jquery.flash_message.js');
echo $html->script('/admin/js/jquery_plugins/jquery.button.js');
echo $html->script('/admin/js/automate/admin_index.js');

?><script type="text/javascript">
jQuery(document).ready(function () {
	jQuery('.cell_bullet a').live('click', function () {
		var list_record = jQuery(this).parents('.list_record').first();
//var list_record_siblings = list_record.siblings();
//jQuery('.list_record_children', list_record_siblings).remove();
//jQuery('.cell_bullet', list_record_siblings).removeClass('cell_bullet_on').addClass('cell_bullet_off').find('a').html('<?php echo $routine->icon('bullet_toggle_plus'); ?>');
		var list_record_parent = jQuery('.list_record_parent', list_record);
		var list_record_children = jQuery('.list_record_children', list_record);
		// remove / close
		if (list_record_children.size() > 0) {
			list_record_children.remove();
			jQuery('.cell_bullet', list_record_parent).removeClass('cell_bullet_on').addClass('cell_bullet_off').find('a').html('<?php echo $routine->icon('bullet_toggle_plus'); ?>');
			return false;
		}
		// add / open
		var id = jQuery('.cell_primary_key', list_record).text();
window.location.hash = '#' + id;
		var url = '<?php echo rtrim($this->base, '/'); ?>/admin/<?php echo $this->params['controller']; ?>/sub_index/' + id + '?' + Math.random();
		jQuery.get(url, {}, function (html) {
			list_record_parent.after('<div class="list_record_children">' + html + '</div>');
			jQuery('.cell_bullet', list_record_parent).removeClass('cell_bullet_off').addClass('cell_bullet_on').find('a').html('<?php echo $routine->icon('bullet_toggle_minus'); ?>');
		}, 'html');
		return false;
	});
});
</script><?php

// list_container
echo '<div class="list list_container">';

// list_caption
echo '<div class="list_caption">' . $caption_for_layout . '</div>';

// list_buttons (admin_index_buttons.ctp)
echo $this->controllerElement('admin_index_buttons');

// list_paginator (admin_index_paginator.ctp)
echo $this->controllerElement('admin_index_paginator');

// list_filter (admin_index_filter.ctp)
echo $this->controllerElement('admin_index_filter');

// list_records
echo '<div class="list_content list_records">';

if (isset($has_items, $item_model) && $has_items && !isset($rubric_id) && !isset($parent_id)) {
echo '<div class="list_record">';
echo '<div class="list_record_parent">';
echo '<div class="left_cells">';
echo '<div class="cell">' . __('all_items_index', TRUE) . '</div>';
// cell_items_index
if (isset($has_items, $item_model) && $has_items) {
	$items_index_icon = 'arrow_right';
	$items_index_url = array('controller' => Inflector::tableize($item_model), 'action' => 'index', 'autoPage' => FALSE);
	echo '<div class="cell cell_menu cell_items_index">' . $html->link($routine->icon($items_index_icon), $items_index_url, array('title' => __('items_index_action', TRUE), 'escape' => FALSE)) . '</div>';
	if (isset($row[0]['num_items'])) {
		echo '<div class="cell cell_num_items">' . $row[0]['num_items'] . '</div>';
	}
}
echo '</div>'; // end of left_cells
echo '</div>'; // end of list_record_parent
echo '</div>'; // end of list_record
}

function print_list_records($rows, &$View, &$line, $level = 0) {
	if (is_array($rows) && !empty($rows)) {
		foreach ($rows as $i => $row) {
			// list_record
			echo '<div class="list_record">';
			// list_record_parent
			echo '<div class="list_record_parent list_record_parent_' . (($line ++ % 2 === 0) ? 'even' : 'odd') . '">';
			// hidden_cells (admin_index_hidden_cells.ctp)
			echo $View->controllerElement('admin_index_hidden_cells', array('i' => $i, 'row' => $row, 'line' => $line, 'level' => $level, 'num_rows' => count($rows)));
			// left_cells (admin_index_left_cells.ctp)
			echo $View->controllerElement('admin_index_left_cells', array('i' => $i, 'row' => $row, 'line' => $line, 'level' => $level, 'num_rows' => count($rows)));
			// right_cells (admin_index_right1_cells.ctp)
			echo $View->controllerElement('admin_index_right1_cells', array('i' => $i, 'row' => $row, 'line' => $line, 'level' => $level, 'num_rows' => count($rows)));
			// right_cells (admin_index_right2_cells.ctp)
			echo $View->controllerElement('admin_index_right2_cells', array('i' => $i, 'row' => $row, 'line' => $line, 'level' => $level, 'num_rows' => count($rows)));
			// right_cells (admin_index_right3_cells.ctp)
			echo $View->controllerElement('admin_index_right3_cells', array('i' => $i, 'row' => $row, 'line' => $line, 'level' => $level, 'num_rows' => count($rows)));
			echo '</div>'; // end of list_record_parent
			// children
			if (isset($row['children']) && is_array($row['children']) && !empty($row['children'])) {
				// list_record_children
				echo '<div class="list_record_children">';
				print_list_records($row['children'], $View, $line, $level + 1);
				echo '</div>'; // end of list_record_children
			}
			echo '</div>'; // end of list_record
		}
	} else {
		// list_record
		echo '<div class="list_record">';
		// list_record_empty
		echo '<div class="list_record_empty">' . __('no_records', TRUE) . '</div>';
		echo '</div>'; // end of list_record
	}
}
$line = 1;
$level = 0;
print_list_records($rows, $this, $line, $level);
echo '</div>'; // end of list_records

// list_paginator (admin_index_paginator.ctp)
echo $this->controllerElement('admin_index_paginator');

// list_buttons (admin_index_buttons.ctp)
echo $this->controllerElement('admin_index_buttons');

echo '</div>'; // end of list_container


?>